<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas style="border: 1px solid black;" id="canvas" width="1000" height="1000"></canvas>
    <script>
        let ctx = document.getElementById("canvas").getContext("2d");;
        let offset = 0;

        function draw() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            // 长度和间距

            // offset为移动的距离
            ctx.lineDashOffset = -offset;
            /* 这是一个图形 */
            context.beginPath();
            ctx.setLineDash([4, 4]);
            context.endPath()

            /* 这是一个图形 */
            context.beginPath();
            ctx.strokeRect(50, 50, 200, 100);
            context.endPath()

        }

        // 递归函数
        function march() {
            offset++;
            if (offset > 16) {
                offset = 0;
            }
            draw();
            setTimeout(march, 100);
        }
    </script>
</body>

</html>